﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Drawing;
using ST.Library.UI.NodeEditor;

namespace STNode_A2B.STNodeControls
{
    /// <summary>
    /// 此类仅演示 作为MixRGB节点的复选框控件
    /// </summary>
    public class STNodeControl_CheckBox : STNodeControl
    {
        private bool _Checked;

        public bool Checked
        {
            get { return _Checked; }
            set
            {
                _Checked = value;
                this.Invalidate();
            }
        }

        public event EventHandler ValueChanged;
        protected virtual void OnValueChanged(EventArgs e)
        {
            if (this.ValueChanged != null) this.ValueChanged(this, e);
        }

        protected override void OnMouseClick(System.Windows.Forms.MouseEventArgs e)
        {
            base.OnMouseClick(e);
            this.Checked = !this.Checked;
            this.OnValueChanged(new EventArgs());
        }

        protected override void OnPaint(DrawingTools dt)
        {
            //base.OnPaint(dt);
            Graphics g = dt.Graphics;
            g.FillRectangle(Brushes.White, 5, 5, 10, 10);
            m_sf.Alignment = StringAlignment.Near;
            g.DrawString(this.Text, this.Font, Brushes.LightGray, new Rectangle(15, 0, this.Width - 20, 20), m_sf);
            if (this.Checked)
            {
                //g.FillRectangle(Brushes.LightGreen, 2, 7, 6, 6);

                // Draw a checkmark (√) inside a rectangle
                using (Pen pen = new Pen(Brushes.Black, 2))
                {
                    // Define the points for the checkmark
                    Point[] points = new Point[]
                    {
                        new Point(5, 10),
                        new Point(8, 13),
                        new Point(14, 7)
                    };

                    // Draw the checkmark
                    g.DrawLines(pen, points);
                }
            }
        }
    }
}
